package com.atguigu2.netty.http;



import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;


/**
 * @author sunfeng
 * @date 2021/03/30 10:59
 **/
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
            // 向管道加入处理器
        ChannelPipeline pipeline = ch.pipeline();

        // 加入一个netty提供的 httpServerCodec codec =>[coder - decoder]
        //1、 HttpServerCodec 是 netty 提供的处理 http 的 编-解码器
        pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());

        // 2、增加一个自定义的handler

        pipeline.addLast("MyTestHttpServerHandler", new TestHttpServerHandler());
//        pipeline.addLast(new StringEncoder(Charset.forName("GBK")));
//        pipeline.addLast(new StringDecoder(StandardCharsets.UTF_8));

    }
}
